import 'dart:convert';

import 'package:flutter/foundation.dart';

class SocketMessageTool {
  String toolKitId;
  List<String> epcList;
  int stockType;
  String storageId;
  SocketMessageTool({
    required this.toolKitId,
    required this.epcList,
    required this.stockType,
    required this.storageId
  });

  SocketMessageTool copyWith({
    String? toolKitId,
    List<String>? epcList,
    int? stockType,
    String? storageId,
  }) {
    return SocketMessageTool(
      toolKitId: toolKitId ?? this.toolKitId,
      epcList: epcList ?? this.epcList,
      stockType: stockType ?? this.stockType,
      storageId: storageId??this.storageId
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'toolKitId': toolKitId,
      'epcList': epcList,
      'stockType': stockType,
      'storageId':storageId,
    };
  }

  factory SocketMessageTool.fromMap(Map<String, dynamic> map) {
    return SocketMessageTool(
      toolKitId: map['toolKitId'] ?? '',
      epcList: List<String>.from(map['epcList']),
      stockType: map['stockType']?.toInt() ?? 0,
      storageId: map['storageId']??''
    );
  }

  String toJson() => json.encode(toMap());

  factory SocketMessageTool.fromJson(String source) =>
      SocketMessageTool.fromMap(json.decode(source));

  @override
  String toString() =>
      'SocketMessageTool(toolKitId: $toolKitId, epcList: $epcList, stockType: $stockType,storageId: $storageId)';

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is SocketMessageTool &&
        other.toolKitId == toolKitId &&
        listEquals(other.epcList, epcList) &&
        other.stockType == stockType&&other.storageId==storageId;
  }

  @override
  int get hashCode =>
      toolKitId.hashCode ^ epcList.hashCode ^ stockType^storageId.hashCode;
}
